package services

import (
	"lottery/dao"
	"lottery/datasource"
	"lottery/models"
)

type ResultService interface {
	Get(id int) *models.TbResult
	GetAll() []models.TbResult
	GetByWinner(userId int) []models.TbResult
	GetByAward(awardId int) []models.TbResult
	GetByEvent(eventId int) []models.TbResult
	CountAll() int64
	CountByEvent(eventId int) int64
	CountByAward(awardId int) int64
	CountByWinner(winnerId int) int64
	Update(data *models.TbResult, columns []string) error
	Create(data *models.TbResult) error
}

type resultService struct {
	dao *dao.ResultDao
}

func (s *resultService) Get(id int) *models.TbResult {
	return s.dao.Get(id)
}

func (s *resultService) GetAll() []models.TbResult {
	return s.dao.GetAll()
}

func (s *resultService) GetByWinner(userId int) []models.TbResult {
	return s.dao.GetByWinner(userId)
}

func (s *resultService) GetByAward(awardId int) []models.TbResult {
	return s.dao.GetByAward(awardId)
}

func (s *resultService) GetByEvent(eventId int) []models.TbResult {
	return s.dao.GetByEvent(eventId)
}

func (s *resultService) CountAll() int64 {
	return s.dao.CountAll()
}

func (s *resultService) CountByEvent(eventId int) int64 {
	return s.dao.CountByEvent(eventId)
}

func (s *resultService) CountByAward(awardId int) int64 {
	return s.dao.CountByAward(awardId)
}

func (s *resultService) CountByWinner(winnerId int) int64 {
	return s.dao.CountByWinner(winnerId)
}

func (s *resultService) Update(data *models.TbResult, columns []string) error {
	return s.dao.Update(data, columns)
}

func (s *resultService) Create(data *models.TbResult) error {
	return s.dao.Create(data)
}

func NewResultService() ResultService {
	return &resultService{dao: dao.NewResultDao(datasource.InstanceDbMaster())}
}
